#-*- coding: utf8 -*-
#/usr/bin/python

import MySQLdb
import ssh5

conn = MySQLdb.connect(host="localhost", user="root", passwd="", db="devops")
cursor = conn.cursor()
sql = "select * from member"
cursor.execute(sql)
data = cursor.fetchall()
if data:
    i = 1
#    print type(data)
#    print data
    t = []
    for d in data:
        print "hosts" + str(i) + ": " +  d[1]
        t.append(d[1])
        i = i + 1
num = raw_input("which one do you want to connect? ")
number = int(num) - 1
#print t[number]
host = t[number]
sql = "select host, port, username, password from member  where host = '%s'" % host
cursor.execute(sql)
data = cursor.fetchall()
if data:
    for d in data:
        print "host: " + d[0]
        print "port: " + str(d[1])
        print "username: " + d[2]
        print "password: " + d[3]
        cmd = "pwd"

        ssh5.ssh5(d[0], int(d[1]), d[2], d[3], cmd)
cursor.close()
conn.close()

